﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using utils;

namespace dal.cgm_production_dao
{
    [DataContract]
    public class User
    {
        [DataMember]
        public int id { get; set; }
        [DataMember]
        public string account { get; set; }
        [DataMember]
        public string pwd { get; set; }
        [DataMember]
        public DateTime create_time { get; set; }
        [DataMember]
        public int active { get; set; }
    }

    public class UserDao
    {
        public static User GetUser(string acount, string pwd)
        {
            string sql = @"SELECT id,account,pwd,create_time,active FROM user WHERE account=@acount and pwd=@pwd";
            List<MySqlParameter> parameters = new List<MySqlParameter>();
            parameters.Add(new MySqlParameter("@acount", acount));
            parameters.Add(new MySqlParameter("@pwd", pwd));
            DataSet ds = MySqlHelper.ExecuteDataset(ConfigString.cgm_production, sql, parameters.ToArray());

            IList<User> list = DataContainerUtil.DataTableToList<User>(ds.Tables[0]);
            if (list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return new User();
            }
        }
    }
}
